package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;

import java.util.ArrayList;

/**
 * 选择大棚数据适配
 */
public class ChoiceGhAdapter extends BaseAdapter{
    private Context context;
    private String [] str;
    public ArrayList<Boolean> arrayList;
    public ArrayList<Boolean> getArrayList() {
        return arrayList;
    }
    public void setArrayList(ArrayList<Boolean> arrayList) {
        this.arrayList = arrayList;
    }
    public ChoiceGhAdapter(Context context,String [] str) {
        this.context = context;
        this.str=str;
    }
    @Override
    public int getCount() {
            return  str.length;
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_va_item, parent, false);
            holder = new ViewHolder();
            holder.ly_va_cicy=(LinearLayout) convertView.findViewById(R.id.ly_va_cicy);
            holder.tv_va_cicy=(TextView) convertView.findViewById(R.id.tv_va_cicy);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
            holder.tv_va_cicy.setText(str[position]);
            if(getArrayList().get(position)){
                holder.ly_va_cicy.setSelected(true);
                holder.tv_va_cicy.setSelected(true);
            }else{
                holder.ly_va_cicy.setSelected(false);
                holder.tv_va_cicy.setSelected(false);
            }
        return convertView;
    }
    private class ViewHolder{
       LinearLayout ly_va_cicy;
       TextView tv_va_cicy;
    }
}
